forum

Home / DeveloperSection / Forums / Remote view in android : Auto Cancel Custom Notification

Remote view in android : Auto Cancel Custom Notification

Anonymous User 3487 30-Dec-2015
I am using remote view to create a custom layout  notification , i want to auto cancel the notification once the user touches it 

MyCode:
RemoteViews remoteView = new RemoteViews(this.getPackageName(), R.layout.notification_layout);      
    NotificationCompat.Builder builder = new NotificationCompat.Builder(MainActivity.this);
    builder.setSmallIcon(R.drawable.ic_launcher);
    Intent intent = new Intent(MainActivity.this, SecondActivity.class);
    PendingIntent pIntent = PendingIntent.getActivity(MainActivity.this, RQST_CODE, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    remoteView.setOnClickPendingIntent(R.id.btnNotification, pIntent);
    builder.setAutoCancel(true);
    builder.setContent(remoteView); 
    Notification notify = builder.build();
    notify.flags |= Notification.FLAG_AUTO_CANCEL;
    NotificationManager notiManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notiManager.notify(NOTY_ID, notify);

Updated on 30-Dec-2015
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By